package com.jvm.jvm.ch1;

import com.jvm.jvm.entity.User;

import java.lang.ref.WeakReference;

public class WeakReferenceOutOfMemory {
    public static void main(String[] args) {
        User user = new User("King", 1);
        WeakReference<User> weakReference = new WeakReference<>(user);
        System.out.println(weakReference.get());

        user = null;
        System.gc();

        // 这里是 null 说明 弱引用对象已经被回收了
        System.out.println(weakReference.get());
    }
}
